package cn.humaohua.study.hadoop.cmdrunner.c5;

import cn.humaohua.study.hadoop.cmdrunner.Test;
import org.apache.hadoop.io.Text;
import org.springframework.stereotype.Component;

import java.nio.ByteBuffer;

/**
 * 遍历Text
 */
@Component
public class TextIterator implements Test {
    @Override
    public void test() throws Exception {
//        Text t = new Text("中华人民共和国");
        Text t = new Text("\u0041\u00DF\uD801\uDC00");
        ByteBuffer buf = ByteBuffer.wrap(t.getBytes(), 0, t.getLength());
        int cp;
        while (buf.hasRemaining() && (cp = Text.bytesToCodePoint(buf)) != -1) {
            System.out.println(Integer.toHexString(cp));
            System.out.println((char) cp);
        }
        /*
        4e2d
        中
        534e
        华
        4eba
        人
        6c11
        民
        5171
        共
        548c
        和
        56fd
        国
         */

        /*
        41
        A
        df
        ß
        10400
        Ѐ
         */
    }
}
